package com.ruoyi.project.training.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.training.domain.Training;
import com.ruoyi.project.training.domain.TrainingCourse;
import com.ruoyi.project.training.service.TrainingService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("website/train")
public class TrainingController extends BaseController {

    private String prefix = "system/train";
    @Autowired
    private TrainingService trainingService;

    private Integer idd;

    @RequiresPermissions("website:train:view")
    @GetMapping()
    public String curricula() {
        return prefix + "/train";
    }

    /**
     * 查询【学生培养计划】列表
     */
    @RequiresPermissions("website:train:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Training training){
        startPage();
        List<Training> list = trainingService.selectTrainList(training);
        //System.out.println("/list:"+list);
        return getDataTable(list);
    }


    /**
     * 查看【学生培养计划】列表
     */
    @RequiresPermissions("website:train:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        System.out.println(id);
        idd = id;
        Training training = trainingService.selectTrainingById(id);
        //mmap.put("tbPlanMain", tbPlanMain);
        /*List<TbTotalCourseMain> list = tbTotalCourseMainMapper.selectTbTotalCourseMainList(null);
        mmap.addAttribute("list",list);*/
        mmap.addAttribute("training",training);
        return prefix + "/edit";
    }

//    @RequiresPermissions("website:train:edit")
    @PostMapping("/edit")
    @ResponseBody
    public TableDataInfo edit2( )
    {
        startPage();
        List<TrainingCourse> list =  trainingService.selectCourseByCode(idd);
        return getDataTable(list);
    }

}


